// 添加茶叶页面返回本地存储
Mock.mock("/js/addTeaGetLocal", "post", function () {
    let tea = localStorage.Tea;
    return tea;
})

// addtea Mock
Mock.mock("/js/addTea", "post", function (teaobj) {
    class Tea {
        constructor(teaid, teaname, teatype, teaimg, teaprice, teadescribe) {
            this.teaid = teaid;
            this.teaname = teaname;
            this.teatype = teatype;
            this.teaimg = teaimg;
            this.teaprice = teaprice;
            this.teadescribe = teadescribe;
        }
    }
    let teaObj = JSON.parse(teaobj.body);
    let teaString = localStorage.Tea;
    if (teaString == "" || teaString == null || teaString == undefined || teaString == []) {
        let tea = new Tea();
        tea.teaid = teaObj.teaid;
        tea.teaname = teaObj.teaname;
        tea.teatype = teaObj.teatype;
        tea.teaimg = teaObj.teaimg;
        tea.teaprice = teaObj.teaprice;
        tea.teadescribe = teaObj.teadescribe;
        let arr = [tea];
        localStorage.Tea = JSON.stringify(arr);
        return true;
    } else {
        let bool = false;
        let teaObj2 = JSON.parse(teaString);
        for (let i = 0; i < teaObj2.length; i++) {
            if (teaObj2[i].teaname == teaObj.teaname) {
                bool = true;
                break;
            }
        }
        if (bool) {
            return false;
        } else {
            let tea = new Tea();
            tea.teaid = teaObj.teaid;
            tea.teaname = teaObj.teaname;
            tea.teatype = teaObj.teatype;
            tea.teaimg = teaObj.teaimg;
            tea.teaprice = teaObj.teaprice;
            tea.teadescribe = teaObj.teadescribe;
            teaObj2.push(tea);
            localStorage.Tea = JSON.stringify(teaObj2);
            return true;
        }
    }
})